package com.meta.platform.contract.domain.aggr;

import com.meta.framework.common.utils.SecurityUtils;
import com.meta.platform.contract.intf.cmd.contractfundrecord.AddContractFundRecordCmd;
import com.meta.platform.contract.intf.cmd.contractfundrecord.UpdateContractFundRecordCmd;
import com.meta.platform.contract.intf.entity.ContractFundRecord;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;


@Data
public class ContractFundRecordDo extends ContractFundRecord {

    public static ContractFundRecordDo of(ContractFundRecord record){
        if (record == null){
            return null;
        }
        ContractFundRecordDo recordDo = new ContractFundRecordDo();
        BeanUtils.copyProperties(record, recordDo);

        return recordDo;
    }

    public static List<ContractFundRecordDo> of(List<ContractFundRecord> records){

        if (CollectionUtils.isEmpty(records)){
            return new ArrayList<>();
        }

        List<ContractFundRecordDo> resList = new ArrayList<>();
        for (ContractFundRecord entity : records) {
            resList.add(ContractFundRecordDo.of(entity));
        }

        return resList;
    }

    public static ContractFundRecordDo create(AddContractFundRecordCmd record){
        if (record == null){
            return null;
        }
        ContractFundRecordDo customerDo = new ContractFundRecordDo();
        BeanUtils.copyProperties(record, customerDo);

        return customerDo;
    }

    public void update(UpdateContractFundRecordCmd updateContractFundRecordCmd){
        Long id = this.getId();
        BeanUtils.copyProperties(updateContractFundRecordCmd, this);
        this.setId(id);
    }
}
